home *** CD-ROM | disk | FTP | other *** search
/ Gold Medal Software 3 / Gold Medal Software - Volume 3 (Gold Medal) (1994).iso / music / melody21.arj / MELODY21.EXE / TONE.C < prev    next >
Text File  |  1992-07-26  |  882b  |  41 lines

  1. /*
  2.                          Function Tone for C. 
  3.      For C compilers without Sound, Delay and Nosound funcions.
  4.       From "C primer plus"  by  M.Waite, S.Prata and D.Martin. 
  5. */
  6.  
  7. #include <dos.h>
  8. #define TIMERMODE 182
  9. #define FREQSCALE 1190000L
  10. #define TIMESCALE 150L    /* You can change it for your computer */
  11. #define T_MODEPORT 67
  12. #define FREQPORT 66
  13. #define BEEPPORT 97
  14. #define ON 79
  15.  
  16. void tone(freq, time)
  17. int freq, time;
  18. {
  19.    int hibyt, lobyt, port;
  20.    long i, count, divisor;
  21.  
  22.  
  23.    count = TIMESCALE * time;
  24.    port = inp(BEEPPORT);
  25.    if (freq > 0)
  26.    {
  27.       divisor = FREQSCALE / freq;
  28.       lobyt = divisor % 256;
  29.       hibyt = divisor / 256;
  30.       outp(T_MODEPORT, TIMERMODE);
  31.       outp(FREQPORT, lobyt);
  32.       outp(FREQPORT, hibyt);
  33.       outp(BEEPPORT, ON);
  34.    }
  35.    for (i = 0;i < count;i++)
  36.    ;
  37.    outp(BEEPPORT, port);
  38. }
  39.  
  40.  
  41.